<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="../common/taglibs.jsp" %>
<%
    response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setDateHeader("Expires", 0);
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<jsp:include page="/page/common/include.jsp"></jsp:include>
<script language="javascript" type="text/javascript">

$(document).ready(function(){
	
	/** 初始化查询面板 */
	$("#searchPanel").panel({
		collapsible:true,
		border:false,
		closable:true
	});
	
	/** 初始化用户信息修改窗口 */
	$("#editDiv").window({
		title:'修改用户信息',
		width:400,
		height:350,
	    modal:true,
	    closed:true,
	    minimizable:false,
	    maximizable:false
	});
	
	/** 初始化用户信息查看窗口 */
	$("#viewDiv").window({
		title:'查看用户信息',
		width:600,
		height:320,
	    modal:true,
	    closed:true,
	    minimizable:false,
	    maximizable:false
	});
	
	/** 初始化用户信息Grid Table */
	$("#gridTable").datagrid({
		title:"用户信息列表",
		url:'<%=request.getContextPath()%>/userInfo/userInfoAction!listUserInfo.do',
		singleSelect:true,
		rownumbers:true,
		striped:true,
		fitColumns:true,
		toolbar:"#toolbar",
		pagination:true,
		columns:[[
       		{field:'loginName',title:'登录名',width:100},
          	{field:'realName',title:'显示名称',width:100},
          	{field:'roleName',title:'角色名称',width:100,align:'right',formatter:roleNameFormatter},
          	{field:'deptNo',title:'部门编号',width:100,align:'right'},
          	{field:'email',title:'邮箱',width:100,align:'right'},
          	{field:'tel',title:'联系电话',width:100,align:'right'},
          	{field:'userStatus',title:'有效状态',width:100,align:'right',formatter:statusFormat},
          	{field:'version',title:'版本号',hidden:true}
     	]],
     	onClickRow:function(rowIndex,rowData){
     		
     	},
     	onBeforeLoad:function(){
     		disableLinkButton();
     	},
		onLoadSuccess:function(){
			enableLinkButton();
			$(".role_name_tooltip").tooltip();
		}
	});
	
	$('#role_search').combobox({
		valueField:'value',
		textField:'name',
		panelHeight:'auto',
		editable:false,
		multiple:true,
		url:'<%=request.getContextPath()%>/roleInfo/roleInfoAction!getRoleInfoComboxValue.do',
		formatter: function(row){
			return "<input type='checkbox' id='ch_search_"+row.value+"'/>"+row.name;
		},
		onLoadSuccess:function(){
			
		},
		onSelect:function(record){
			document.getElementById("ch_search_"+record.value).checked = true;
		},
		onUnselect:function(record){
			document.getElementById("ch_search_"+record.value).checked = false;
		}
	});
	
});

/**
 * 角色名称Tooltip格式化显示
 */
function roleNameFormatter(value,rowData){
	return "<span class='role_name_tooltip' title='"+value+"'>"+value+"</span>";
}

/**
 * 格式化用户信息状态
 */
function statusFormat(value,rowData){
	if(value == '0'){
		return '<span style="color:green;">启用</span>';
	}else if(value == '1'){
		return '<span style="color:red;">停用</span>';
	}
}

/**
 * 用户信息查询
 */
function userInfoSearch(){
	$("#loginName_search").val($.trim($("#loginName_search").val()));
	$("#realName_search").val($.trim($("#realName_search").val()));
	$("#gridTable").datagrid("load",{
		loginName:$("#loginName_search").val(),
		realName:$("#realName_search").val()
	});
}

/**
 * 清空查询条件
 */
function clearSearchCriteria(){
	goToPage('<%=request.getContextPath()%>/userInfo/userInfoAction!initManageUserInfo.do');
}

/**
 * 修改用户信息
 */
function edit(){
	var rowData = $('#gridTable').datagrid('getSelected');
	if(rowData == null){
		messageAlertWarning("操作提示","请选择要修改的用户信息！");
		return;
	}
	$.ajax({
		url : '<%=request.getContextPath()%>/userInfo/userInfoAction!initEditUserInfo.do',
		type : 'post',
		dataType : 'text',
		cache : false,
		data : {
			userId : rowData.userId,
			version : rowData.version
		},
		success : function(data) {
			var j = JSON.parse(data);
			if (j.result = 'success') {
				var userInfo = JSON.parse(j.msg);
				var editSystemInfoDiv = initEditWindow(userInfo);
				editSystemInfoDiv.window("open");
			} else {
				$.messager.alert('通知', j.msg,'warn');
				$("#gridTable").datagrid("reload");
			}
		}
	});
}

/**
 * 初始化修改窗口
 */
function initEditWindow(userInfo){
	   return $("#editDiv").window({
					onBeforeOpen:function(){
						$("#userId_edit").val(userInfo.userId);
						$("#version_edit").val(userInfo.version);
						$("#loginName_edit").val(userInfo.loginName);
						$("#realName_edit").val(userInfo.realName);
						$("#password_edit").val(userInfo.password);
						$("#deptNo_edit").val(userInfo.deptNo);
						$("#email_edit").val(userInfo.email);
						$("#tel_edit").val(userInfo.tel);
						$("#birthday_edit").val(userInfo.birthday);
						$('#role_edit').combobox({
							valueField:'value',
							textField:'name',
							panelHeight:'auto',
							editable:false,
							multiple:true,
							formatter: function(row){
								return "<input type='checkbox' id='ch_edit_"+row.value+"'/>"+row.name;
							},
							url:'<%=request.getContextPath()%>/roleInfo/roleInfoAction!getRoleInfoComboxValue.do',
							onLoadSuccess:function(){
								var arry = (userInfo.roleId).split(",");
								$('#role_edit').combobox("setValues",arry);
								for(var i=0;i<arry.length;i++){
									document.getElementById("ch_edit_"+arry[i]).checked = true;
								}
							},
							onChange:function(newValue,oldValue){
								$("#roleId_edit").val(newValue);
							},
							onSelect:function(record){
								document.getElementById("ch_edit_"+record.value).checked = true;
							},
							onUnselect:function(record){
								document.getElementById("ch_edit_"+record.value).checked = false;
							}
						});
					},
					onBeforeClose:function(){
						
					}
				});
}

/**
 * 修改窗口提交
 */
function editWindowSubmit() {
	$.ajax({
		url : '<%=request.getContextPath()%>/userInfo/userInfoAction!editUserInfo.do',
		type : 'post',
		dataType : 'text',
		cache : false,
		data : {
			'userInfo.userId' : $("#userId_edit").val(),
			'userInfo.version' : $("#version_edit").val(),
			'userInfo.loginName' : $("#loginName_edit").val(),
			'userInfo.realName' : $("#realName_edit").val(),
			'userInfo.password' : $("#password_edit").val(),
			'userInfo.deptNo' : $("#deptNo_edit").val(),
			'userInfo.email' : $("#email_edit").val(),
			'userInfo.tel' : $("#tel_edit").val(),
			'userInfo.birthday' : $("#birthday_edit").val(),
			'userInfo.roleId' : $("#roleId_edit").val()
		},
		success : function(data) {
			var j = JSON.parse(data);
			if (j.result = 'success') {
				$.messager.alert('操作结果', '用户信息修改成功！', 'info');
				editWindowClose();
				$("#gridTable").datagrid("reload");
			} else {
				$.messager.alert('操作结果', j.msg, 'error');
			}
		}
	});
}

/**
 * 关闭修改窗口
 */
function editWindowClose() {
	$("#editDiv").window("close");
}

/**
 * 删除用户信息
 */
function remove(){
	var rowData = $('#gridTable').datagrid('getSelected');
	if(rowData == null){
		messageAlertWarning("操作提示","请选择要删除的用户信息！");
		return;
	}
	messageConfirm("操作提示",'你确定要删除所选的用户信息吗?',removeCallback);
}

/**
 * 删除操作回调函数
 */
function removeCallback(){
	var rowData = $('#gridTable').datagrid('getSelected');
	$.ajax({
		url : '<%=request.getContextPath()%>/userInfo/userInfoAction!deleteUserInfo.do',
		type : 'post',
		dataType : 'text',
		cache : false,
		data : {
			userId : rowData.userId,
			version : rowData.version
		},
		success : function(data) {
			var j = JSON.parse(data);
			if (j.result = 'success') {
				$.messager.alert('操作结果', '用户信息删除成功！','info');
				$("#gridTable").datagrid("reload");
			} else {
				$.messager.alert('操作结果', j.msg,'error');
			}
		}
	});
}

/**
 * 查看
 */
function view(){
	var rowData = $('#gridTable').datagrid('getSelected');
	if(rowData == null){
		messageAlertWarning("操作提示","请选择要查看的用户信息！");
		return;
	}
	$.ajax({
		url : '<%=request.getContextPath()%>/userInfo/userInfoAction!initEditUserInfo.do',
		type : 'post',
		dataType : 'text',
		cache : false,
		data : {
			userId : rowData.userId,
			version : rowData.version
		},
		success : function(data) {
			var j = JSON.parse(data);
			if (j.result = 'success') {
				var userInfo = JSON.parse(j.msg);
				var viewUserInfoDiv = initViewWindow(userInfo);
				viewUserInfoDiv.window("open");
			} else {
				$.messager.alert('通知', j.msg,'warn');
				$("#gridTable").datagrid("reload");
			}
		}
	});
}

/**
 * 初始化查看窗口
 */
function initViewWindow(userInfo){
	   return $("#viewDiv").window({
			onBeforeOpen:function(){
				$("#loginName_view").text(userInfo.loginName);
				$("#realName_view").text(userInfo.realName);
				$("#password_view").text(userInfo.password);
				$("#roleName_view").text(userInfo.roleName);
				$("#deptNo_view").text(userInfo.deptNo);
				$("#email_view").text(userInfo.email);
				$("#tel_view").text(userInfo.tel);
				$("#birthday_view").text(userInfo.birthday);
				var userStatusNameFormat = "";
				if(userInfo.userStatus == '0'){
					userStatusNameFormat = "<span style='color:green;'>"+userInfo.userStatusName+"</span>";
				}else if(userInfo.userStatus == '1'){
					userStatusNameFormat = "<span style='color:red;'>"+userInfo.userStatusName+"</span>";
				}
				$("#userStatusName_view").html(userStatusNameFormat);
				$("#lastLoginIp_view").text(userInfo.lastLoginIp);
				$("#lastLoginTime_view").text(userInfo.lastLoginTime);
				$("#recordCrtOperLoginName_view").text(userInfo.recordCrtOperLoginName);
				$("#recordCrtTime_view").text(userInfo.recordCrtTime);
				$("#recordUpdOperLoginName_view").text(userInfo.recordUpdOperLoginName);
				$("#recordUpdTime_view").text(userInfo.recordUpdTime);
				$("#version_view").text(userInfo.version);
			},
			onBeforeClose:function(){
				
			}
		});
}

/**
 * 关闭查看窗口
 */
function viewWindowClose() {
	$("#viewDiv").window("close");
}
</script>
</head>

<body style="background: white;" >
	<!-- 查询面板 -->
	<div id="searchPanel" style="width:'100%';height:95px;padding:20px;" align="center">
		<table>
			<tr>
				<td>登录名：<input id="loginName_search" type="text" style="width:100px"/></td>
				<td>显示名：<input id="realName_search" type="text" style="width:100px"/></td>
				<td>角色：<input id="role_search" style="width:150px;"/></td>
			</tr>
			<tr>
				<td colspan="3" align="center" style="padding-top: 10px">
					<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="userInfoSearch()">查询</a>
					<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-reload" onclick="clearSearchCriteria()">清空</a>
				</td>
			</tr>
		</table>
	</div>
	
	<!-- 工具栏 -->
	<div id="toolbar" style="padding:5px;">
		<a href="javascript:void(0)" id="editBtn" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'" onclick="edit()">修改</a>
		<a href="javascript:void(0)" id="removeBtn" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'" onclick="remove()">删除</a>
		<a href="javascript:void(0)" id="viewBtn" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'" onclick="view()">查看</a>
	</div>
	
	<!-- 数据Table -->
	<table id="gridTable" style="width:'90%';height:'100%'">
	</table>
	
	<!-- 编辑窗口 -->
	<div id="editDiv" style="padding:10px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;" align="center">
		    	<table>
		    		<input id="userId_edit" type="hidden" />
		    		<input id="version_edit" type="hidden" />
		    		<input id="roleId_edit" type="hidden" />
		    		<tr>
		    			<td>登录名:</td>
		    			<td>
		    				<input id="loginName_edit" type="text" disabled="disabled"/>
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>显示名称:</td>
		    			<td>
		    				<input id="realName_edit" type="text" />
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>密码:</td>
		    			<td>
		    				<input id="password_edit" type="text" />
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>角色:</td>
		    			<td>
		    				<input id="role_edit" style="width:154px;">
							</input>
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>部门编号:</td>
		    			<td>
		    				<input id="deptNo_edit" type="text" />
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>邮箱:</td>
		    			<td>
		    				<input id="email_edit" type="text" />
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>联系电话:</td>
		    			<td>
		    				<input id="tel_edit" type="text" />
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>出生日期 :</td>
		    			<td>
		    				<input id="birthday_edit" type="text" size="20" cssClass="Wdate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'%y-%M-{%d}'})"/>
		    			</td>
		    		</tr>
		    	</table>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="editWindowSubmit()">提交</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="editWindowClose()">取消</a>
			</div>
		</div>
	</div>
	
	<!-- 查看窗口 -->
	<div id="viewDiv" style="padding:10px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;" align="center">
		    	<table class="view_table">
	    			<tr>
		    			<th>登录名</th>
		    			<td id="loginName_view"/>
		    			<th>显示名称</th>
		    			<td id="realName_view"/>
		    		</tr>
		    		<tr>
		    			<th>密码</th>
		    			<td id="password_view"/>
		    			<th>角色</th>
		    			<td id="roleName_view"/>
		    		</tr>
		    		<tr>
		    			<th>部门编号</th>
		    			<td id="deptNo_view"/>
		    			<th>邮箱</th>
		    			<td id="email_view"/>
		    		</tr>
		    		<tr>
		    			<th>联系电话</th>
		    			<td id="tel_view"/>
		    			<th>出生日期 </th>
		    			<td id="birthday_view"/>
		    		</tr>
		    		<tr>
		    			<th>用户状态 </th>
		    			<td id="userStatusName_view"/>
		    			<th>最后一次登录IP</th>
		    			<td id="lastLoginIp_view"/>
		    		</tr>
		    		<tr>
		    			<th>最后一次登录时间 </th>
		    			<td id="lastLoginTime_view"/>
		    			<th>记录创建人</th>
		    			<td id="recordCrtOperLoginName_view"/>
		    		</tr>
		    		<tr>
		    			<th>记录创建时间</th>
		    			<td id="recordCrtTime_view"/>
		    			<th>记录更新人</th>
		    			<td id="recordUpdOperLoginName_view"/>
		    		</tr>
		    		<tr>
		    			<th>记录更新时间</th>
		    			<td id="recordUpdTime_view"/>
		    			<th>版本号</th>
		    			<td id="version_view"/>
		    		</tr>
		    	</table>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="viewWindowClose()">关闭</a>
			</div>
		</div>
	</div>
</body>
</html>